<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');



// extends CI controller, add Session and Cookie check
class MY_Controller extends CI_Controller {
		
	protected $template = array();   //array of holding template information	
		
		
		
	// check user session and cookie
	public function __construct(){
		    parent::__construct();   //inherit parent construcotr
		    
		    $this -> template['url'] = $this ->router ->fetch_method();   //keep current method and class  name
			$this -> template['class'] = $this ->router -> fetch_class();
		
            if ( $this->router->fetch_class() != 'login' ) {   // do not check login class
		         if (!CheckLoginInfo()) {   //check cookie or session		   
                        $redirect = $this->uri->uri_string();     //get current URL           
                       if ( $_SERVER['QUERY_STRING']) {         //get parameter after ?
                          $redirect .= '?' . $_SERVER['QUERY_STRING'];
                       }
		               		               
		               redirect( LOGIN_PAGE('?redirect=' . $redirect) );    //If cookie or session is not available then goto login page
		         }
            } 
	}
	
}
